<?php 
if(isset($_REQUEST['ip']))
	$ip=$_REQUEST['ip'];
else 
	$ip=$_SERVER['REMOTE_ADDR'];
$x = gethostbyname($ip);
//echo $x."<br>";
$ip_long=sprintf('%u',ip2long($x));
//echo $ip_long."<br>";
$row = 1;
if (($handle = fopen("GeoIPCountryWhois.csv", "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
       // echo "<p> $num fields in line $row: <br /></p>\n";
        $row++;
       // for ($c=0; $c < $num; $c++) {
        	
       //     echo $data[$c] . "<br />\n";
            
       // }
        if($data[2]<= $ip_long && $ip_long <= $data[3]){
        	echo $data[4];
        	break;
        }
    }
    fclose($handle);
}

?>